import React, { useEffect, useState } from 'react';
import { Form } from 'antd';
import { AxInput, AxSelectTree } from '@/components/AxForm/AxFormItem';
import { AxAdvancedSearchDrawer } from '@/components/AxForm/AxSearchForm/AxAdvancedSearchDrawer';
import { axurl } from '@/shared/axurl';
import { axhttp } from '@/shared/axhttp';
import { axhelper } from '@/shared/axhelper';

const url = axurl.store.goods.data;
const { getDataX } = axhttp;
const Search: React.FC<any> = props => {
    const { form, values = {}, ...rest } = props;
    const [categorys, setCategorys] = useState<any>([]);

    useEffect(() => {
        getDataX(url.readCategory).then((res: any) => {
            setCategorys(axhelper.transToStandardData(res.list, 'id', 'text'));
        });
    }, []);

    return (
        <AxAdvancedSearchDrawer
            form={form}
            {...rest}
        >
            <AxInput
                form={form}
                label="CAS编码"
                field="casCode"
                value={values.casCode}
                wholerow='none'
            />
            <AxInput
                form={form}
                label="产品名称"
                field="name"
                wholerow='none'
            />
            <AxSelectTree
                form={form}
                label="产品分类"
                field="categoryId"
                wholerow='none'
                data={categorys}
            />,
        </AxAdvancedSearchDrawer>
    );
};

export default Form.create<any>()(Search);
